Imports PTT.CarRes.Data

Public Class ClassQueryInvHuman
    Public Function Add(ByVal InvHuman As QueryInvHuman, ByVal StrConn As String) As Boolean
        Dim ClsInvHuman As New ClassInvHuman
        Dim Conn As OleDb.OleDbConnection
        Conn = ClsInvHuman.ConnectionOpen(StrConn)
        Dim ret As Boolean = False
        With ClsInvHuman
            .HumanId = InvHuman.HumanId
            .Name = InvHuman.Name
            .ReserveId = InvHuman.ReserveId
            ret = .USP_Save(Conn)
        End With
        ClsInvHuman.ConnectionClose(Conn)
        Return ret
    End Function

    Public Function Edit(ByVal InvHuman As QueryInvHuman, ByVal StrConn As String) As Boolean
        Dim ClsInvHuman As New ClassInvHuman
        Dim Conn As OleDb.OleDbConnection
        Conn = ClsInvHuman.ConnectionOpen(StrConn)
        Dim ret As Boolean = False
        With ClsInvHuman
            .HumanId = InvHuman.HumanId
            .Load(Conn)
            .Name = InvHuman.Name
            .ReserveId = InvHuman.ReserveId
            ret = .USP_Update(Conn)
        End With
        ClsInvHuman.ConnectionClose(Conn)
        Return ret
    End Function

    Public Function Delete(ByVal InvHuman As QueryInvHuman, ByVal StrConn As String) As Boolean
        Dim ClsInvHuman As New ClassInvHuman
        Dim Conn As OleDb.OleDbConnection
        Conn = ClsInvHuman.ConnectionOpen(StrConn)
        Dim ret As Boolean = False
        With ClsInvHuman
            .HumanId = InvHuman.HumanId
            .Load(Conn)
            ret = .USP_Delete(Conn)
        End With
        ClsInvHuman.ConnectionClose(Conn)
        Return ret
    End Function

    Public Function Search(Optional ByVal ParaHumanId As String = "", _
    Optional ByVal ParaName As String = "", _
    Optional ByVal ParaReserveId As String = "", Optional ByVal StrConn As String = "") As QueryInvHumans
        Dim ClsInvHuman As New ClassInvHuman
        Dim Conn As OleDb.OleDbConnection
        Conn = ClsInvHuman.ConnectionOpen(StrConn)
        Dim ret As QueryInvHumans = Nothing
        Dim str As String = ""
        Dim Condition As String = ""
        str &= " Select * from InvHuman"
        If ParaHumanId & "" <> "" Then
            If Condition & "" <> "" Then
                Condition &= " and "
            End If
            Condition &= "(HumanId = " & ParaHumanId & ")"
        End If
        If ParaName & "" <> "" Then
            If Condition & "" <> "" Then
                Condition &= " and "
            End If
            Condition &= "(Name like '%" & ParaName & "%')"
        End If
        If ParaReserveId & "" <> "" Then
            If Condition & "" <> "" Then
                Condition &= " and "
            End If
            Condition &= "(ReserveId = " & ParaReserveId & ")"
        End If

        If Condition & "" <> "" Then
            str &= " where "
            str &= Condition
        End If
        Dim ds As DataSet
        With ClsInvHuman
            ds = .BindData(Conn, , , str)
            If Not ds Is Nothing Then
                Dim i As Integer
                Dim results As New QueryInvHumans

                Try
                    For i = 0 To ds.Tables(0).Rows.Count - 1
                        With ds.Tables(0).Rows(i)

                            results.Add(New QueryInvHuman( _
                              .Item("HumanId") & "", _
                              .Item("Name") & "", _
                              .Item("ReserveId") & "" _
                            ))
                        End With
                    Next
                    ret = results
                Catch ex As Exception
                    Return Nothing
                    'Throw New DALException(ex.Message)
                End Try
            End If
        End With
        ClsInvHuman.ConnectionClose(Conn)
        Return ret
    End Function
    Public Function Load(Optional ByVal ParaHumanId As String = "", _
    Optional ByVal ParaReserveId As String = "", Optional ByVal StrConn As String = "") As QueryInvHumans
        Dim ClsInvHuman As New ClassInvHuman
        Dim Conn As OleDb.OleDbConnection
        Conn = ClsInvHuman.ConnectionOpen(StrConn)
        Dim ret As QueryInvHumans = Nothing
        Dim str As String = ""
        Dim Condition As String = ""
        str &= " Select * from InvHuman"
        If ParaHumanId & "" <> "" Then
            If Condition & "" <> "" Then Condition &= " and "
            Condition &= "(HumanId = " & ParaHumanId & ")"
        End If
        If ParaReserveId & "" <> "" Then
            If Condition & "" <> "" Then Condition &= " and "
            Condition &= "(ReserveId = " & ParaReserveId & ")"
        End If

        If Condition & "" <> "" Then
            str &= " where "
            str &= Condition
        Else
            Return Nothing
            Exit Function
        End If
        Dim ds As DataSet
        With ClsInvHuman
            ds = .BindData(Conn, , , str)
            If Not ds Is Nothing Then
                Dim i As Integer
                Dim results As New QueryInvHumans

                Try
                    For i = 0 To ds.Tables(0).Rows.Count - 1
                        With ds.Tables(0).Rows(i)

                            results.Add(New QueryInvHuman( _
                              .Item("HumanId") & "", _
                              .Item("Name") & "", _
                              .Item("ReserveId") & "" _
                            ))
                        End With
                    Next
                    ret = results
                Catch ex As Exception
                    Return Nothing
                    'Throw New DALException(ex.Message)
                End Try
            End If
        End With
        ClsInvHuman.ConnectionClose(Conn)
        Return ret
    End Function
End Class